﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;


namespace JogoQualquer
    {
    class Player
        {
            int player;
            Texture2D texture;
            Vector2 position;
            GameWindow window;
            Color color;
            public Player(Texture2D texture, Vector2 position, GameWindow window, int player, Color color)
            {
                this.texture = texture;
                this.position = position;
                this.window = window;
                this.player = player;
                this.color = color;
                
            }

            public void Update(KeyboardState ks)
            {

                #region Movimentação
                if (player == 1)
                {
                    if (ks.IsKeyDown(Keys.Right))
                    {
                        this.position.X += 5;
                    }

                    if (ks.IsKeyDown(Keys.Left))
                    {
                        this.position.X -= 5;
                    }

                    if (ks.IsKeyDown(Keys.Up))
                    {
                        this.position.Y -= 5;
                    }

                    if (ks.IsKeyDown(Keys.Down))
                    {
                        this.position.Y += 5;
                    }

                }

                if (player == 2)
                {
                    if (ks.IsKeyDown(Keys.D))
                    {
                        this.position.X += 5;
                    }

                    if (ks.IsKeyDown(Keys.A))
                    {
                        this.position.X -= 5;
                    }

                    if (ks.IsKeyDown(Keys.W))
                    {
                        this.position.Y -= 5;
                    }

                    if (ks.IsKeyDown(Keys.S))
                    {
                        this.position.Y += 5;
                    }

                }

                #endregion

                #region Colisao borda da tela
                if (this.position.X + this.texture.Bounds.Width > window.ClientBounds.Width)
                {
                    this.position.X = window.ClientBounds.Width - this.texture.Bounds.Width;
                }

                if (this.position.X <= 0)
                {
                    this.position.X = 0;
                }

                if (this.position.Y + this.texture.Bounds.Height > window.ClientBounds.Height)
                {
                    this.position.Y = window.ClientBounds.Height - this.texture.Bounds.Height;
                }

                if (this.position.Y <= 0)
                {
                    this.position.Y = 0;
                }
                #endregion

            }

            public void Draw(SpriteBatch spriteBatch)
            {


                 spriteBatch.Draw(texture, position, color);


            }
        
        }
    }
